//namespace ContosoUniversity.Services.QueryServices
//{
//    using System;
//    using System.Collections.Generic;
//    using System.Dynamic;
//    using System.Linq;
//    using System.Threading.Tasks;
//    using ContosoUniversity.Models;
//    using NRepository.Core.Query;
//    using NRepository.EntityFramework.Query;

//    public class CourseControllerQueryService : ICourseControllerQueryService
//    {
//        private readonly IQueryRepository _QueryRepository;

//        public CourseControllerQueryService(IQueryRepository queryRepository)
//        {
//            _QueryRepository = queryRepository;
//        }

//        public async Task<ExpandoObject> GetAllCoursesAsync(int? SelectedDepartment)
//        {
//            dynamic retVal = new ExpandoObject();
//            retVal.Departments = await _QueryRepository.GetEntitiesAsync<Department>(
//                new OrderByQueryStrategy<Department>(p => p.Name),
//                new AsNoTrackingQueryStrategy());

//            int departmentID = SelectedDepartment.GetValueOrDefault();
//            var courses = await _QueryRepository.GetEntitiesAsync<Course>(
//                c => !SelectedDepartment.HasValue || c.DepartmentID == departmentID,
//                new OrderByQueryStrategy<Course>(p => p.CourseID),
//                new EagerLoadingQueryStrategy<Course>(p => p.Department),
//                new AsNoTrackingQueryStrategy());

//                retVal.Courses =courses.Select(course => new CourseQueryModel
//                {
//                    CourseID = course.CourseID,
//                    Credits = course.Credits,
//                    DepartmentName = course.Department.Name,
//                    Title = course.Title,
//                    DepartmentID = course.DepartmentID
//                });

//            return retVal;
//        }

//        public async Task<IEnumerable<Department>> GetOrderedDepartmentsAsync()
//        {
//            var departmentsQuery = _QueryRepository.GetEntitiesAsync<Department>(
//                    new AsNoTrackingQueryStrategy(),
//                    new OrderByDescendingQueryStrategy("Name"));

//            return await departmentsQuery;
//        }

//        public async Task<Course> GetCourseAsync(int id)
//        {
//            return await _QueryRepository.GetEntityAsync<Course>(p => p.CourseID == id, false);
//        }
//    }
//}
